<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no" />
    <link rel="stylesheet" href="__CSS__/common.css">
    <link rel="stylesheet" href="__CSS__/loan.css">
    <link rel="stylesheet" href="__CSS__/nav.css">
    <title>我贷款</title>
</head>
<body>
    <div class="loan-box">
    </div>
    {include file="footer" /}
</body>
<script src="__JS__/jquery.min.js"></script>
<script type="text/javascript">
    var page = 1, //分页码
        off_on = false, //分页开关(滚动加载方法 1 中用的)
        timers = null; //定时器(滚动加载方法 2 中用的)

    var Loadpage = function(page) {
        $.ajax({
            type:'post',
            url:'/index/index/loan.html',
            data:{pageNo:page,pageSize:10},
            success:function (data){
                var dom = '';
                for (var p of data.data ) {
                    dom += `
                      <div class="loan-item">
                        <div class="item-img">
                            <img src="${p.thumb}" alt="${p.name}">
                            <p>${p.name}</p>
                        </div>
                        <div class="item-font">
                            <p><span>${p.credit_line}</span>/最高额度</p>
                            <p><span>${p.desc}</span>|<span>${p.spend}</span>${p.unit}</p>
                        </div>
                        <button class="btn" onclick="loanDetail(${p.id})">立即申请</button>
                    </div>
                        `
                }
                $('.loan-box').append(dom);
            },
            error:function () {alert(data.msg);}
        });
        off_on = true;
    };
    $(document).ready(function() {
        Loadpage();
    });
    $(window).scroll(function() {
        if (($(window).height() + $(window).scrollTop() + 60) >= $(document).height()) {
            clearTimeout(timers);
            timers = setTimeout(function() {
                page++;
                // console.log("第" + page + "页");
                Loadpage(page);
            }, 300);
        }
    });
    function loanDetail(id) {
        location.href="{:url('index/loanDetail')}"+"?type=1&pid="+id;
    }
</script>
</html>